define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'technician/technician/index' + location.search,
                    // add_url: 'technician/technician/add',
                    edit_url: 'technician/technician/edit',
                    // del_url: 'technician/technician/del',
                    multi_url: 'technician/technician/multi',
                    import_url: 'technician/technician/import',
                    table: 'technician',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'technician_id',
                sortName: 'technician_id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'technician_id', title: __('技师id')},
                        {field: 'uid', title: __('Uid')},
                        {field: 'technician_name', title: __('Technician_name'), operate: 'LIKE'},
                        {field: 'technician_avatar', title: __('Technician_avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'technician_age', title: __('Technician_age'), operate: 'LIKE'},
                        {field: 'technician_gender', title: __('Technician_gender'), searchList: {"0":__('Technician_gender 0'),"1":__('Technician_gender 1')}, formatter: Table.api.formatter.normal},
                        {field: 'license', title: __('License'), operate: 'LIKE',events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'store.name', title: __('店铺名称')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'real_name', title: __('Real_name'), operate: 'LIKE'},
                        {field: 'identity', title: __('Identity'), operate: 'LIKE'},
                        // {field: 'education_status', title: __('Education_status'), searchList: {"0":__('Education_status 0'),"1":__('Education_status 1'),"2":__('Education_status 2'),"3":__('Education_status 3'),"4":__('Education_status 4'),"5":__('Education_status 5')}, formatter: Table.api.formatter.status},
                        {field: 'nation', title: __('Nation'), operate: 'LIKE'},
                        {field: 'height', title: __('Height'), operate:'BETWEEN'},
                        {field: 'weight', title: __('Weight'), operate:'BETWEEN'},
                        // {field: 'lon', title: __('Lon'), operate: 'LIKE'},
                        // {field: 'lat', title: __('Lat'), operate: 'LIKE'},
                        {field: 'zodiak', title: __('Zodiak'), operate: 'LIKE'},
                        {field: 'constellation', title: __('Constellation'), operate: 'LIKE'},
                        {field: 'technician_phone', title: __('Technician_phone'), operate: 'LIKE'},
                        {field: 'recommend_status', title: __('Recommend_status'), searchList: {"1":__('Recommend_status 1'),"2":__('Recommend_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'identity_positive', title: __('Identity_positive'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'identity_reverse', title: __('Identity_reverse'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'health_cards', title: __('Health_cards'), operate: 'LIKE',events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'technician_status', title: __('Technician_status'), searchList: {"1":__('Technician_status 1'),"2":__('Technician_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'technician_address', title: __('Technician_address'), operate: 'LIKE'},
                        {field: 'is_telephone', title: __('Is_telephone'), searchList: {"0":__('Is_telephone 0'),"1":__('Is_telephone 1')}, formatter: Table.api.formatter.normal},
                        {field: 'is_join_store', title: __('Is_join_store'), searchList: {"0":__('Is_join_store 0'),"1":__('Is_join_store 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'serve_time', title: __('服务时间开始'),operate: 'LIKE'},
                        {field: 'service_area', title: __('Service_area'), operate: 'LIKE'},
                        {field: 'is_check', title: __('Is_check'), searchList: {"0":__('Is_check 0'),"1":__('Is_check 1')}, formatter: Table.api.formatter.normal},
                        {field: 'feedback', title: __('Feedback'), operate: 'LIKE'},
                        // {field: 'serve_time_end', title: __('Serve_time_end')},
                        {field: 'technicianlabel.technician_label', title: __('技师标签'), operate: 'LIKE'},
                        // {field: 'work_day', title: __('Work_day'), operate: 'LIKE'},
                        {field: 'serve_scope', title: __('Serve_scope'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('按钮组'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'servelog',
                                    text: __('服务列表'),
                                    title: __('服务列表'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'store/technicianserve/index?technician_id={ids}',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                                // {
                                //     name: 'detail',
                                //     text: __('位置'),
                                //     title: __('位置'),
                                //     classname: 'btn btn-xs btn-primary btn-dialog',
                                //     icon: 'fa fa-map-marker',
                                //     url: 'technician/technician/amap',
                                //     callback: function (data) {
                                //         Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                //     },
                                //     visible: function (row) {
                                //         //返回true时按钮显示,返回false隐藏
                                //         return true;
                                //     }
                                // },
                                // {
                                //     name: 'money',
                                //     text: __('佣金记录'),
                                //     title: __('佣金记录'),
                                //     classname: 'btn btn-xs btn-primary btn-dialog',
                                //     icon: 'fa fa-map-marker',
                                //     url: 'user/user_money_log/index?technician_uid={uid}',
                                //     callback: function (data) {
                                //         Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                //     },
                                //     visible: function (row) {
                                //         //返回true时按钮显示,返回false隐藏
                                //         return true;
                                //     }
                                // },
                            ],

                            formatter: Table.api.formatter.buttons
                        }

                        ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
